/**
 * Module dependencies.
 */

var https = require('https');
var fs = require('fs');
var express = require('express');
var app = express();

var options = {
    key: fs.readFileSync('key.pem'),
    cert: fs.readFileSync('cert.pem')
};

// all environments
app.set('port', 8080);
app.get('/git/*',function(req, res) {
    console.log(req.params);
    fs.readFile(__dirname + '/' + req.params[0], function(err, data) {
        if(req.params[0].search(/html$/)>0) {
            console.log("html file");
            res.writeHead(200, { 'Content-Type': 'text/html'});
        } else if(req.params[0].search(/js$/)>0) {
            console.log("js file");
            res.writeHead(200, { 'Content-Type': 'text/javascript'});
        } else if(req.params[0].search(/css$/)>0) {
            console.log("css file");
            res.writeHead(200, { 'Content-Type': 'text/css'});
        }
        res.end(data);
    });
});

/*
app.get('/git/*', function(req, res, next) {
    console.log("redirect");
    console.log(req.url);
    fs.readFile(__dirname + '/' + req.url, function(err, data) {
        if(req.url.search(/html$/)>0) {
            console.log("html file");
            res.writeHead(200, { 'Content-Type': 'text/html'});
        } else if(req.url.search(/js$/)>0) {
            console.log("js file");
            res.writeHead(200, { 'Content-Type': 'text/javascript'});
        } else if(req.url.search(/css$/)>0) {
            console.log("css file");
            res.writeHead(200, { 'Content-Type': 'text/css'});
        }
        res.end(data);
    });
});
*/

https.createServer(options, app).listen(app.get('port'), function() {
  console.log('Express server listening on port ' + app.get('port'));
});

/*
https.createServer(options, function(req, res) {
    console.log(req.url);
    fs.readFile(__dirname + '/' + req.url, function(err, data) {
        if(req.url.search(/html$/)>0) {
            console.log("html file");
            res.writeHead(200, { 'Content-Type': 'text/html'});
        } else if(req.url.search(/js$/)>0) {
            console.log("js file");
            res.writeHead(200, { 'Content-Type': 'text/javascript'});
        } else if(req.url.search(/css$/)>0) {
            console.log("css file");
            res.writeHead(200, { 'Content-Type': 'text/css'});
        }
        res.end(data);
    });
}).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
*/
